﻿Imports Microsoft.VisualBasic

Imports System.IO
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Globalization
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Imports System.Diagnostics
Imports System.Net
Imports System.Collections.Generic

Public NotInheritable Class GFunctions

#Region "DataType check and Convert"
    Public Shared Function IsFloat(ByVal strNum As String) As Boolean
        Try
            Single.Parse(strNum)
        Catch
            Return False
        End Try
        Return True
    End Function

    Public Shared Function DoubleToString(ByVal dblNum As Double) As String
        Dim str As String = "0"

        If dblNum <> 0 Then
            str = String.Format("{0:#,##0.00}", dblNum)
        End If
        Return str
    End Function
#End Region

#Region "Client Information"
    Public Shared Function GetServerIP() As String
        Dim ipEntry As IPHostEntry
        Dim strHostName As String

        strHostName = Dns.GetHostName()
        ipEntry = Dns.GetHostEntry(strHostName)
        Dim strFromIP As String = ipEntry.AddressList(0).ToString()
        Return strFromIP
    End Function

    Public Shared Function GetRootOrVirtual() As String
        Dim mstrAppPath As String = HttpContext.Current.Request.ApplicationPath.ToLower()
        ' A site
        If mstrAppPath = "/" Then
            mstrAppPath = "/"
            'A virtual
        ElseIf Not mstrAppPath.EndsWith("/") Then
            mstrAppPath += "/"
        End If

        Return mstrAppPath
    End Function

    Public Shared Function GetDefaultValue(ByVal pValue As String, ByVal pComparedValue As String, ByVal pReturnValue As String) As String
        If (pValue = pComparedValue) Then
            Return pReturnValue
        Else
            Return pValue
        End If
    End Function

#End Region

#Region "DB "

    Public Shared Function GetPostCodeID(ByVal sPostCodeDesc As String, ByVal gConn As GDataConnection) As Long
        Dim mSQLExec As String = "" & "Exec" & vbTab & "spGetPostCodeID '" & sPostCodeDesc & "'"

        Return Long.Parse(gConn.ExecuteScalar(mSQLExec).ToString())
    End Function
    Public Shared Function GetCompanyID(ByVal sCompanyName As String, ByVal gConn As GDataConnection) As Long
        Dim mSQLExec As String = "" & "Exec" & vbTab & "spGetCompanyID '" & sCompanyName & "' "

        Return Long.Parse(gConn.ExecuteScalar(mSQLExec).ToString())
    End Function

    Public Shared Function UpdateDB(ByVal pDataTable As DataTable, ByVal pTableName As String, ByVal gConn As GDataConnection) As Boolean
        Dim bResult As Boolean = True
        Try
            Dim mSQL As String = "SELECT * FROM " & pTableName
            Dim mDataAdapter As New SqlDataAdapter(mSQL, gConn.Conn)
            Dim mCommandBuilder As New SqlCommandBuilder(mDataAdapter)
            mDataAdapter.Update(pDataTable)
        Catch e As Exception
            Dim str As String = e.Message
            bResult = False
        End Try

        Return bResult
    End Function

#End Region

#Region "DataGrid"


    Public Shared Sub LoadDataToDataGrid(ByVal dGrid As DataGrid, ByVal strSql As String, ByVal gConn As GDataConnection)
        Dim dataSet As DataSet = Nothing
        Dim dataAdapter As SqlDataAdapter = Nothing

        Try
            dataSet = New DataSet()
            dataAdapter = New SqlDataAdapter(strSql, gConn.Conn)
            dataAdapter.Fill(dataSet)
            'Load data
            dGrid.DataSource = Nothing
            dGrid.DataBind()

            dGrid.DataSource = dataSet
            dGrid.DataBind()
        Catch err As Exception
            If err.Message = "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount." Then
                dGrid.CurrentPageIndex = 0
                dGrid.DataBind()
            Else
                Throw err
            End If
        Finally
            dataAdapter.Dispose()
            dataSet.Clear()

            dataSet.Dispose()
        End Try
    End Sub


    Public Shared Sub LoadDataToDataGrid(ByVal dGrid As GridView, ByVal strSql As String, ByVal gConn As GDataConnection)
        Dim dataSet As DataSet = Nothing
        Dim dataAdapter As SqlDataAdapter = Nothing

        Try
            dataSet = New DataSet()
            dataAdapter = New SqlDataAdapter(strSql, gConn.Conn)
            dataAdapter.Fill(dataSet)
            'Load data
            dGrid.DataSource = Nothing
            dGrid.DataBind()

            dGrid.DataSource = dataSet
            dGrid.DataBind()
        Catch ex As Exception
            Dim strErr As String
            strErr = ex.Message
        Finally
            dataAdapter.Dispose()
            dataSet.Clear()

            dataSet.Dispose()
        End Try
    End Sub

    ''' <summary>
    ''' Load data from database to a DataGrid throw a DataView object
    ''' </summary>
    ''' <param name="dGrid">The DataGrid to load data to</param>
    ''' <param name="strSql">The query string to get data from database</param>
    ''' <param name="gConn">The connection to connect to database</param>
    ''' <param name="strFilter">The string to filter data</param>
    Public Shared Sub LoadDataToDataGridByView(ByVal dGrid As DataGrid, ByVal strSql As String, ByVal gConn As GDataConnection, ByVal strFilter As String)
        Dim dataSet As DataSet = Nothing
        Dim dataAdapter As SqlDataAdapter = Nothing
        Dim view As DataView = Nothing

        Try
            dataSet = New DataSet()
            dataAdapter = New SqlDataAdapter(strSql, gConn.Conn)
            dataAdapter.Fill(dataSet)
            view = New DataView(dataSet.Tables(0))
            view.RowFilter = strFilter

            dGrid.DataSource = Nothing
            dGrid.DataBind()

            dGrid.DataSource = view
            dGrid.DataBind()
        Catch err As Exception
            If err.Message = "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount." Then
                dGrid.CurrentPageIndex = 0
                dGrid.DataBind()
            Else
                Throw err
            End If
        Finally
            dataAdapter.Dispose()
            dataSet.Clear()
            dataSet.Dispose()
        End Try
    End Sub

    Public Shared Sub ClearDataGrid(ByVal dg As DataGrid)
        dg.DataSource = Nothing
        dg.DataBind()
    End Sub

    Public Shared Sub ShowGridOrder(ByVal grv As GridView, ByVal col As Integer)
        Dim pIndex As Integer = 0

        If (grv.PageIndex > 0) Then
            pIndex = grv.PageIndex
        End If

        Dim startRowNo As Integer = grv.PageIndex * grv.PageSize

        For i As Integer = 1 To grv.Rows.Count
            grv.Rows(i - 1).Cells(col).Text = (i + startRowNo).ToString()
        Next
    End Sub
#End Region

#Region "DropDownList"


    Public Shared Sub LoadDataForDropDownList(ByVal list As DropDownList, ByVal strSql As String, ByVal strFirstRow As String)

        



        Dim command As SqlCommand = Nothing
        Dim reader As SqlDataReader = Nothing

        If strFirstRow <> "" Then
            list.Items.Clear()
            list.Items.Add(New ListItem(strFirstRow, "-1"))
        End If

        Dim gConn As SqlConnection = Nothing

        Try
            
        Catch ex As Exception
            Throw (New Exception("Connection to database server failed." & ex.Message))
        End Try

        Try
            gConn = New SqlConnection(Define.ConnStr)
            gConn.Open()

            If gConn.State <> ConnectionState.Open Then
                gConn.Open()
            End If
            command = New SqlCommand(strSql, gConn)
            reader = command.ExecuteReader()
            While reader.Read()
                list.Items.Add(New ListItem(reader(0).ToString(), reader(1).ToString()))
            End While
            list.SelectedIndex = 0
        Catch e As Exception
            Dim str As String = e.Message
        Finally
            If reader IsNot Nothing AndAlso Not reader.IsClosed Then
                reader.Close()
            End If
            If command IsNot Nothing Then
                command.Dispose()
            End If
            If (gConn.State = ConnectionState.Open) Then
                gConn.Close()
                gConn.Dispose()
            End If
        End Try
    End Sub

    Public Shared Sub LoadDataForDropDownList(ByVal list As DropDownList, ByVal strSql As String, ByVal gConn As GDataConnection, ByVal strFirstRow As String)
        Dim command As SqlCommand = Nothing
        Dim reader As SqlDataReader = Nothing

        If strFirstRow <> "" Then
            list.Items.Clear()
            list.Items.Add(New ListItem(strFirstRow, "-1"))
        End If

        Try
            If gConn.Conn.State <> ConnectionState.Open Then
                gConn.Conn.Open()
            End If
            command = New SqlCommand(strSql, gConn.Conn)
            reader = command.ExecuteReader()
            While reader.Read()
                list.Items.Add(New ListItem(reader(0).ToString(), reader(1).ToString()))
            End While
            list.SelectedIndex = 0
        Catch e As Exception
            Dim str As String = e.Message
        Finally
            If reader IsNot Nothing AndAlso Not reader.IsClosed Then
                reader.Close()
            End If
            If command IsNot Nothing Then
                command.Dispose()
            End If
        End Try
    End Sub

    Public Shared Sub LoadDataForDropDownListAllBlank(ByVal list As DropDownList, ByVal strSql As String, ByVal gConn As GDataConnection, ByVal strFirstRow As String)
        Dim command As SqlCommand = Nothing
        Dim reader As SqlDataReader = Nothing

        If strFirstRow <> "" Then
            list.Items.Clear()
            list.Items.Add(New ListItem(strFirstRow, ""))
        End If

        Try
            If gConn.Conn.State <> ConnectionState.Open Then
                gConn.Conn.Open()
            End If
            command = New SqlCommand(strSql, gConn.Conn)
            reader = command.ExecuteReader()
            While reader.Read()
                list.Items.Add(New ListItem(reader(0).ToString(), reader(1).ToString()))
            End While
            list.SelectedIndex = 0
        Catch e As Exception
            Dim str As String = e.Message
        Finally
            If reader IsNot Nothing AndAlso Not reader.IsClosed Then
                reader.Close()
            End If
            If command IsNot Nothing Then
                command.Dispose()
            End If
        End Try
    End Sub

    Public Shared Sub LoadDataForDropDownList(ByVal pDropDownList As DropDownList, ByVal pSQLStatment As String, ByVal pGDataConnection As GDataConnection)
        Dim mSqlCommand As SqlCommand = Nothing
        Dim mSqlDataReader As SqlDataReader = Nothing

        pDropDownList.Items.Clear()

        Try
            If pGDataConnection.Conn.State <> ConnectionState.Open Then
                pGDataConnection.Conn.Open()
            End If
            mSqlCommand = New SqlCommand(pSQLStatment, pGDataConnection.Conn)
            mSqlDataReader = mSqlCommand.ExecuteReader()

            While mSqlDataReader.Read()
                pDropDownList.Items.Add(New ListItem(mSqlDataReader(0).ToString(), mSqlDataReader(1).ToString()))
            End While

            pDropDownList.SelectedIndex = 0
        Catch e As Exception
            Dim str As String = e.Message
        Finally
            If mSqlDataReader IsNot Nothing AndAlso Not mSqlDataReader.IsClosed Then
                mSqlDataReader.Close()
            End If
            If mSqlCommand IsNot Nothing Then
                mSqlCommand.Dispose()
            End If
        End Try
    End Sub
    Public Shared Sub LoadDataForDropDownList(ByVal list As DropDownList, ByVal strSql As String, ByVal gConn As GDataConnection, ByVal strFirstRow As String, ByVal bShowFirstRow As Boolean)
        If bShowFirstRow Then
            LoadDataForDropDownList(list, strSql, gConn, strFirstRow)
        Else
            LoadDataForDropDownList(list, strSql, gConn, "")
            list.Items.RemoveAt(0)
        End If

    End Sub

    Public Shared Sub LoadEnumForDropDownList(ByVal lList As DropDownList, ByVal tEnum As Type)
        lList.Items.Clear()

        For Each val As Short In [Enum].GetValues(tEnum)
            lList.Items.Add(New ListItem([Enum].GetName(tEnum, val).Replace("_", " "), val.ToString()))
        Next
    End Sub

    Public Shared Sub LoadEnumForDropDownList(ByVal lList As DropDownList, ByVal tEnum As Type, ByVal strFirstItem As String)
        lList.Items.Clear()
        lList.Items.Add(New ListItem(strFirstItem, "-1"))
        For Each val As Short In [Enum].GetValues(tEnum)
            lList.Items.Add(New ListItem([Enum].GetName(tEnum, val).Replace("_", " "), val.ToString()))
        Next
    End Sub

    Public Shared Sub SelectIndexForDropDownList(ByVal list As DropDownList, ByVal strValue As String)
        For i As Integer = 0 To list.Items.Count - 1
            If list.Items(i).Value = strValue OrElse (IsFloat(list.Items(i).Value) = True AndAlso IsFloat(strValue) = True AndAlso Single.Parse(list.Items(i).Value) = Single.Parse(strValue)) Then
                list.SelectedIndex = i
                Return
            End If
        Next
    End Sub
#End Region

#Region "ListBox"

    Public Shared Sub LoadDataForListBox(ByVal list As ListBox, ByVal strSql As String, ByVal gConn As GDataConnection, ByVal strFirstRow As String)
        Dim command As SqlCommand = Nothing
        Dim reader As SqlDataReader = Nothing

        list.Items.Clear()
        If strFirstRow.Length > 1 Then
            list.Items.Add(New ListItem(strFirstRow, "-1"))
        End If
        Try
            command = New SqlCommand(strSql, gConn.Conn)
            reader = command.ExecuteReader()
            While reader.Read()
                list.Items.Add(New ListItem(reader(0).ToString(), reader(1).ToString()))
            End While
        Catch generatedExceptionName As Exception
        Finally
            If reader IsNot Nothing AndAlso Not reader.IsClosed Then
                reader.Close()
            End If
            If command IsNot Nothing Then
                command.Dispose()
            End If
        End Try
    End Sub

    Public Shared Sub SelectIndexForListBox(ByVal list As ListBox, ByVal strValue As String)
        list.Items(0).Selected = False
        For i As Integer = 0 To list.Items.Count - 1
            If ("," & strValue & ",").IndexOf("," & list.Items(i).Value & ",") >= 0 Then
                list.Items(i).Selected = True
            End If
        Next
        Return
    End Sub
#End Region

#Region "RadioButtionList"

    Public Shared Sub SelectIndexForRadioButtonList(ByVal list As RadioButtonList, ByVal strValue As String)
        For i As Integer = 0 To list.Items.Count - 1
            If list.Items(i).Value = strValue OrElse (IsFloat(list.Items(i).Value) = True AndAlso IsFloat(strValue) = True AndAlso Single.Parse(list.Items(i).Value) = Single.Parse(strValue)) Then
                list.SelectedIndex = i
                Return
            End If
        Next
    End Sub

#End Region

#Region "Enum"


    Public Shared Function GetEnumName(ByVal shtValue As Short, ByVal tEnum As Type) As String
        Return [Enum].GetName(tEnum, shtValue)
    End Function

    Public Shared Function GetEnumValues(ByVal tEnum As Type) As ArrayList
        Dim alValues As New ArrayList()

        For Each val As Short In [Enum].GetValues(tEnum)
            alValues.Add(val)
        Next
        Return alValues
    End Function
#End Region

#Region "Special String"

    Public Shared Function ReplaceSpecialChars(ByVal strString As String) As String
        If strString Is Nothing Then
            Return ""
        Else
            Return strString.Replace("'", "''")
        End If
    End Function

    Public Shared Function ReplaceNewRowToBRChars(ByVal strString As String) As String
        If strString Is Nothing Then
            Return ""
        Else
            Return strString.Replace(vbCr & vbLf, "<br>")
        End If
    End Function

    Public Shared Function RemoveSpecialChars(ByVal strString As String) As String
        Dim strSpecialChars As String

        strSpecialChars = "'()"
        For Each c As Char In strSpecialChars.ToCharArray()
            strString = strString.Replace(c, " "c)
        Next
        strString = strString.Replace(" ", "")
        If strString Is Nothing Then
            Return ""
        Else
            Return strString.Replace("'", "''")
        End If
    End Function

    Public Shared Function RemoveSpecialCharsInFileName(ByVal pFileName As String) As String
        For Each mChar As Char In pFileName.ToCharArray()
            Dim mASCII As Integer = Convert.ToInt32(mChar)
            ' a - z
            If mASCII >= 65 AndAlso mASCII <= 90 Then
                Continue For
            End If
            ' A - Z
            If mASCII >= 97 AndAlso mASCII <= 122 Then
                Continue For
            End If

            ' 0 - 9
            If mASCII >= 48 AndAlso mASCII <= 57 Then
                Continue For
            End If

            ' Space - _ ( ) . 
            If mASCII = Convert.ToInt32(" "c) OrElse mASCII = Convert.ToInt32("-"c) OrElse mASCII = Convert.ToInt32("_"c) OrElse mASCII = Convert.ToInt32("("c) OrElse mASCII = Convert.ToInt32(")"c) OrElse mASCII = Convert.ToInt32("."c) Then
                Continue For
            End If

            pFileName = pFileName.Replace(mChar.ToString(), "")
        Next

        Return pFileName
    End Function
#End Region

#Region "DateTime Format"


    Public Shared Function GetddMMMyyyyFormat(ByVal objDate As DateTime) As String
        If objDate <> DateTime.MinValue Then
            Dim format As System.IFormatProvider = New System.Globalization.CultureInfo("en-US", True)

            Return objDate.ToString("dd MMM yyyy", format)
        Else
            Return ""
        End If
    End Function

    Public Shared Function GetVietNamDateFormat(ByVal objDate As DateTime) As String
        If objDate <> DateTime.MinValue Then
            Return objDate.ToString("dd/MM/yyyy")
        Else
            Return ""
        End If
    End Function

    Public Shared Function StringToDateTime(ByVal strDateTime As String) As DateTime
        If strDateTime <> "" Then
            Return Convert.ToDateTime(strDateTime, New CultureInfo("ru-RU"))
        Else
            ' MinValue represents NULL
            Return DateTime.MinValue
        End If
    End Function

    ''' <summary>
    ''' Change string in dd/mm/yyyy format to dd/mmm/yyyy style
    ''' </summary>
    ''' <param name="strDate"></param>
    ''' <returns></returns>
    '''  <Design>Khang</Design>
    Public Shared Function ChangeDate(ByVal strDate As String) As String
        If strDate = "" Then
            Return ""
        End If
        Dim strMonth As String = strDate.Substring(strDate.IndexOf("/") + 1, strDate.LastIndexOf("/") - strDate.IndexOf("/") - 1)
        Dim Month As String() = {"", "Jan", "Feb", "Mar", "Apr", "May", _
         "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", _
         "Dec"}
        strDate = strDate.Replace("/" & strMonth & "/", "/" & Month(Convert.ToInt32(strMonth)) & "/")
        Return strDate
    End Function

    Public Shared Function GetLocalDateFormat(ByVal objDate As DateTime) As String
        If objDate <> DateTime.MinValue Then
            Return objDate.ToString("dd/MM/yyyy")
        Else
            Return ""
        End If
    End Function

    Public Shared Function CompareDatetime(ByVal t1 As DateTime, ByVal t2 As DateTime) As String
        Dim result As Integer = System.DateTime.Compare(t1, t2)
        If result >= 0 Then
            Return " is earlier than "
        End If
        Return ""
    End Function

#End Region

#Region "MD5"

    Public Shared Function GetMD5(ByVal pwd As String) As String
        Dim md5 As New MD5CryptoServiceProvider()
        Dim bHash As Byte() = md5.ComputeHash(Encoding.UTF8.GetBytes(pwd))
        Dim sbHash As New StringBuilder()

        For Each b As Byte In bHash
            sbHash.Append([String].Format("{0:x2}", b))
        Next
        Return sbHash.ToString()
    End Function

#End Region

#Region "File and Folder"

    Public Shared Function CreateFolderName(ByVal strName As String) As String
        Dim strInvalidChar As String = "\/:*?\<>|"
        Dim cInvalidChar As Char()
        Dim i As Integer = 0, iLength As Integer

        strInvalidChar += """"
        iLength = strName.Length
        cInvalidChar = strInvalidChar.ToCharArray()
        While i >= 0
            i = strName.IndexOfAny(cInvalidChar)
            If i >= 0 Then
                strName = strName.Substring(0, i) & "-" & strName.Substring(i + 1, iLength - i - 1)
            End If
        End While

        Return strName
    End Function
#End Region

#Region "CheckBoxList"

    Public Shared Sub ShowCheckBoxListValue(ByVal list As CheckBoxList, ByVal data As DataTable, ByVal valueField As String)

        For i As Integer = 0 To list.Items.Count - 1
            For j As Integer = 0 To data.Rows.Count - 1
                If list.Items(i).Value = data.Rows(j)(valueField).ToString() Then
                    list.Items(i).Selected = True
                End If
            Next
        Next
    End Sub



    Public Shared Function GetCheckBoxListvalue(ByVal list As CheckBoxList) As String
        Dim sVal As String = "(-1"
        For i As Integer = 0 To list.Items.Count - 1
            If list.Items(i).Selected = True Then
                sVal += "," & list.Items(i).Value
            End If
        Next
        sVal += ")"
        Return sVal
    End Function
    Public Shared Function GetCheckBoxListValueID(ByVal chk As CheckBoxList) As String
        Dim strValueList As String = ""
        For Each li As ListItem In chk.Items
            If li.Selected Then
                strValueList += li.Value & ","
            End If
        Next
        If strValueList.Trim() <> "" Then
            strValueList = strValueList.Substring(0, strValueList.Length - 1)
        End If

        Return strValueList
    End Function
#End Region

#Region "SQL Select Field"

    Public Shared Function CreateMeaningFullEnumSQL(ByVal tEnum As Type) As String
        Return CreateMeaningFullEnumSQL(tEnum, tEnum.Name.ToString())
    End Function

    Public Shared Function CreateMeaningFullEnumSQL(ByVal tEnum As Type, ByVal fieldName As String) As String
        Return CreateMeaningFullEnumSQL(tEnum, fieldName, fieldName)
    End Function

    Public Shared Function CreateMeaningFullEnumSQL(ByVal tEnum As Type, ByVal fieldName As String, ByVal [alias] As String) As String
        Dim strSql As String = "(case " & fieldName

        For Each val As Short In [Enum].GetValues(tEnum)
            strSql += " when " & val.ToString() & " then N'" & [Enum].GetName(tEnum, val).Replace("_", " ") & "' "
        Next

        Return strSql & " else 'None' end ) as " & [alias]

        '(case BOMStatus when 0 then 'In Progress'when 1 then 'Issued'else 'Khong biet' end) as BomStatus

    End Function

#End Region

    Public Shared Function GetNotAvailableQCID(ByVal gConn As GDataConnection) As String
        Dim strSql As String
        Dim objID As Object

        strSql = "Select Top 1 QCID From tblQCNote Where QCNo like 'N/A'"
        objID = gConn.ExecuteScalar(strSql)
        If (objID IsNot Nothing) AndAlso (Convert.ToString(objID) <> "null") Then
            Return Convert.ToString(objID)
        End If
        Return Nothing
    End Function

    Public Shared Function DoLogin(ByVal strUserName As String, ByVal strPass As String, ByVal para As InitPara) As Boolean
        Dim spPara As SqlParameter() = New SqlParameter(5) {}

        spPara(0) = New SqlParameter("@UserName", SqlDbType.NVarChar, 50)
        spPara(0).Direction = ParameterDirection.Input
        spPara(0).Value = strUserName

        spPara(1) = New SqlParameter("@Password", SqlDbType.VarChar, 200)
        spPara(1).Direction = ParameterDirection.Input
        spPara(1).Value = strPass

        spPara(2) = New SqlParameter("@ID", SqlDbType.VarChar, 50)
        spPara(2).Direction = ParameterDirection.Output

        spPara(3) = New SqlParameter("@UserTypeID", SqlDbType.TinyInt)
        spPara(3).Direction = ParameterDirection.Output

        spPara(4) = New SqlParameter("@FullName", SqlDbType.VarChar, 250)
        spPara(4).Direction = ParameterDirection.Output

        spPara(5) = New SqlParameter("@LoginSuccess", SqlDbType.Bit)
        spPara(5).Direction = ParameterDirection.Output

        If para.GConnection.ExecuteStoreProcedure("spDoLogin", spPara) Then
            If (Not (TypeOf spPara(5).Value Is DBNull)) AndAlso Convert.ToBoolean(spPara(5).Value) Then
                'Login successful
                para.UserID = Convert.ToString(spPara(2).Value)
                para.UserTypeID = Convert.ToInt16(spPara(3).Value)
                para.FullName = Convert.ToString(spPara(4).Value)
                para.UserName = strUserName
                para.passWord = strPass

                Return True
            End If
        End If
        Return False
    End Function

    'Public Shared Function DoLogin(ByVal strUserName As String, ByVal strPassword As String, ByVal pInitPara As InitPara) As Boolean
    '    Dim strSQL As String = "SELECT COUNT(*) Result FROM tblUser WHERE UserName=@UserName AND Password=@Password"
    '    Dim lParam As List(Of SqlParameter) = New List(Of SqlParameter)
    '    lParam.Add(New SqlParameter("@UserName", strUserName))
    '    lParam.Add(New SqlParameter("@Password", GetMD5(strPassword)))

    '    Dim lParamArray As SqlParameter() = lParam.ToArray()

    '    Dim bLoginResult As Boolean = False

    '    If (pInitPara IsNot Nothing) Then

    '        'If (pInitPara.GConnection.ExecuteStoreProcedure("DoLogin", lParamArray)) Then
    '        '    bLoginResult = True
    '        'End If

    '        If (pInitPara.GConnection.ExecuteCommandText(strSQL, lParamArray).ToString() = "1") Then
    '            bLoginResult = True
    '        End If

    '    End If

    '    If bLoginResult Then
    '        pInitPara.UserName = strUserName

    '        Return True
    '    End If

    '    Return False
    'End Function

End Class
